<%--
  Created by IntelliJ IDEA.
  User: 86132
  Date: 2022/10/31
  Time: 20:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<html>
<head>
    <base href="<%= basePath%>">
<%--    引入jquery--%>
    <script src="js/jquery-3.6.0.min.js"></script>
    <title>Title</title>
</head>
<script type="text/javascript">
    $(function (){
        //用户名文本框失去焦点时做表单验证
        $("#userName").blur(function (){
            var userName = $("#userName").val()
            //表单验证(不只是是否为空的判断)
            if (userName == ""){
                $("#userNameSpan").html("用户名不能为空")
            }
        })
        //用户名文本框获得焦点时做表单验证
        $("#userName").focus(function (){
            $("#userNameSpan").html("")
        })
        //密码文本框失去焦点时做表单验证
        $("#password").blur(function (){
            var password = $("#password").val()
            //表单验证(不只是是否为空的判断)
            if (password == ""){
                $("#passwordSpan").html("密码不能为空")
            }
        })
        //密码文本框获得焦点时做表单验证
        $("#password").focus(function (){
            $("#passwordSpan").html("")
        })

        //注册按钮绑定单机事件
        $("#registerBtn").click(function (){
            //表单验证
            var userName=$("#userName").val()
            var password=$("#password").val()
            if (userName == ""){
                $("#registerTipSpan").html("用户名不能为空")
                return
            }
            if (password == ""){
                $("#registerTipSpan").html("密码不能为空")
                return;
            }
            $.ajax({
                url : "settings/qx/user/register.do",
                dataType : "json",
                type : "POST",
                data : {
                    userName : userName,
                    password : password
                },
                success : function (resp){
                    if (resp.code == 1){
                        window.location.href="workbench/index.do"
                    }else {
                        $("#registerTipSpan").html(resp.message)
                    }
                }
            })
        })
    })
</script>
<body>

用户名:<input type="text" id="userName"><span id="userNameSpan"></span><br>
密码:<input type="password" id="password"><span id="passwordSpan"></span><br>
<span id="registerTipSpan"></span><br>
<input type="button" id="registerBtn" value="注册">
</body>
</html>
